﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace Hsinchu.Utility
{
    /*
     * Http处理类
     */
    public class HttpHandle
    {
        /// <summary>
        /// 获得Request参数,返回String类型
        /// </summary>
        /// <param name="_params">参数名称</param>
        /// <author>grokyao</author>
        /// <date>2010-1-14</date>
        /// <returns>string</returns>
        public static string GetParamsString(string _params)
        {
            try
            {
                return HttpContext.Current.Request.QueryString[_params].ToString();
            }
            catch (System.InvalidCastException ice)
            {
                ErrorHandle.Log(ice.ToString());
                RedirectErrorPage(ice.Message);
                return "";
            }
        }


        /// <summary>
        /// 获得Request参数,返回int类型
        /// </summary>
        /// <param name="_params">参数名称</param>
        /// <author>grokyao</author>
        /// <date>2010-1-14</date>
        /// <returns>int</returns>
        public static int GetParamsInt(string _params)
        {
            try
            {
                return Convert.ToInt32(HttpContext.Current.Request.QueryString[_params]);
            }
            catch (System.InvalidCastException ice)
            {
                ErrorHandle.Log(ice.ToString());
                RedirectErrorPage(ice.Message);
                return 0;
            }
        }


        /// <summary>
        /// 指定跳转页面
        /// </summary>
        /// <param name="url">页面url</param>
        /// <author>grokyao</author>
        /// <date>2009-2-23</date>
        public static void RedirectPage(string url)
        {
            HttpContext.Current.Response.Redirect(url);
        }


        /// <summary>
        /// 跳往错误页
        /// </summary>
        /// <param name="errormessage">错误信息</param>
        /// <author>grokyao</author>
        /// <date>2009-2-23</date>
        public static void RedirectErrorPage(string errormessage)
        {
            HttpContext.Current.Response.Redirect(HttpContext.Current.Server.MapPath("~/")+errormessage);
        }
    }
}
